package com.ruoyi.collection.controller;

import com.ruoyi.collection.domian.Collection;
import com.ruoyi.collection.mapper.CollectionMapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/collection/collection")
public class CollectionController extends BaseController {

    @Autowired
    private CollectionMapper collectionMapper;

    /**
     * 招聘信息收藏
     * @param jobId
     * @return
     */

    @PreAuthorize("@ss.hasPermi('work:jobbasicinfo:collection')")
    @Log(title = "岗位job管理", businessType = BusinessType.OTHER)
    @GetMapping("/collect/{jobId}")
    public AjaxResult collection(@PathVariable Long jobId){
        Collection collection=new Collection();
        collection.setJob_id(jobId);
        collection.setUser_id(getUserId());
        int count=collectionMapper.addCollection(collection);
        if (count>0){
            return success("收藏成功");
        }
        return error("收藏失败");
    }


    /**
     * 删除我的收藏
     */
    @PreAuthorize("@ss.hasPermi('collection:collection:remove')")
    @Log(title = "岗位job管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jobIds}")
    public AjaxResult remove(@PathVariable Long[] jobIds)
    {
        return toAjax(collectionMapper.deleteCollection(jobIds));
    }
}
